#include <regx52.h>
int time=0;
int time_seed;
unsigned int i;
/**
 * 实现一个按键，每次点击按键点亮8个灯中随机数量，随机位置的灯
 * 保证至少有一个灯被点亮
 */
void timer0_init()
{
    TMOD &= 0xF0;
    TMOD |= 0x01;

    TH0 = 0xDB;

    TL0 = 0xFF;

    TR0 = 1;

    ET0 = 1;

    EA = 1;
    
    PT0 = 1;
}

unsigned int timer_rand()
{
    time_seed = (time * 123 + 255) % 255;
    if(time_seed==0)
    {
      time_seed=time_seed+1;
    }
    return time_seed;
}

void timer0_ISR() interrupt 1
{
    
  TH0 = 0xDB;
    
  TL0 = 0xFF;

  time=time+1;

}
void main()
{
    timer0_init();
    while(1)
    {
      if(P1_0==0)
      {
       while(P1_0==0){}
       i=timer_rand();
       P2=~i;
      }

    }
}
